package com.finiac.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;


import com.finiac.model.FeeStructure;



public class FeeStructureDAOImpl implements FeeStructureDAO {

	
private HibernateTemplate hibernateTemplate;
	
	public void setSessionFactory(SessionFactory sessionFactory){
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	
	@SuppressWarnings("unchecked")
	@Override
	public List<FeeStructure> listAll() {
		return hibernateTemplate.find("from FeeStructure where isActive=1");
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<FeeStructure> listFeeStructure() {
		return hibernateTemplate.find("from FeeStructure where isActive = 1 order by id");
	}


	@Override
	public void addFeeStruct(FeeStructure feeStructure) {
		hibernateTemplate.saveOrUpdate(feeStructure);
		
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<FeeStructure> selectByIdList(int id) {
		return hibernateTemplate.find("from FeeStructure where id="+ id +"and isActive=1");
	}
	
	
	
	@Override
	public void addFeeStructure(FeeStructure feeStructure) {
		hibernateTemplate.saveOrUpdate(feeStructure);

}
	@SuppressWarnings("unchecked")
	@Override
	public List<FeeStructure> selectByStudent(long admissionNo) {
		return hibernateTemplate.find("from FeeStructure where admissionNo ="+admissionNo+" and isActive=1");
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public FeeStructure selectByAdmissionNo(long admissionNo) {
		FeeStructure feeStructure= new FeeStructure();
		List<FeeStructure> feeStructureList= hibernateTemplate.find("from FeeStructure where admissionNo="+admissionNo +" and isActive =1");
		for(int i=0;i<feeStructureList.size();i++)
		{
			feeStructure = feeStructureList.get(i);
		}
		return feeStructure;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<FeeStructure>selectById(int id) {
		return hibernateTemplate.find("from FeeStructure where id="+id + " and isActive = 1");
	}
	@Override
	public void updateFeeStructure(FeeStructure feeStructure) {
		hibernateTemplate.update(feeStructure);
	}
}
